package com.bb.blog.code.nio;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

public class NettyByteBuf {
    public static void main(String[] args) {
        // 1. 创建ByteBuf对象
        // 2. 通过 reader index 和 writerIndex  capacity 将buffer分成三个区域
        // 3. 已经读取的区域 [0,readerIndex]
        // 4. 可读取的区域  [readIndex, writeIndex]
        // 5. 可写的区域 [writerIndex, capacity]
        ByteBuf byteBuf = Unpooled.buffer(10);
        for (int i = 0; i < 8; i++) {
            byteBuf.writeByte(i+10);
        }
        System.out.println("byteBuf="+byteBuf);

        for (int j = 0; j < 7; j++) {
            System.out.println(byteBuf.getByte(j));
        }

        for (int i = 0; i < 8; i++) {
            System.out.println(byteBuf.readByte());

        }
        System.out.println(byteBuf);

    }
}
